#include"queue.h"

void QLInit(QL* q)
{
	assert(q);
	q->head = NULL;
	q->tail = NULL;
	q->size = 0;
}
void QLPush(QL* q, QDateType x)
{
	assert(q);
	QNode* newnode = (QNode*)malloc(sizeof(QNode));
	newnode->x = x;
	newnode->next = NULL;
	if (q->head == NULL)
	{
		q->head = q->tail = newnode;
	}
	else
	{
		q->tail->next = newnode;
		q->tail = newnode;
	}
	q->size++;
}
void QLPop(QL* q)
{
	assert(q);
	assert(q->head != NULL);
	if (q->head->next == NULL)
	{
		q->head = q->tail = NULL;
	}
	else
	{
		QNode* next = q->head->next;
		free(q->head);
		q->head = next;
	}
	q->size--;
}
QDateType QLFront(QL* q)
{
	assert(q);
	assert(q->head != NULL);
	return q->head->x;
}
QDateType QLBack(QL* q)
{
	assert(q);
	assert(q->tail != NULL);
	return q->tail->x;
}
int QLSize(QL* p)
{
	assert(p);
	return p->size;
}
bool QLEmpty(QL* p)
{
	assert(p);
	return p->head == NULL;
}
void QLDestroy(QL* p)
{
	assert(p);
	QNode* pcur = p->head;
	while (pcur)
	{
		QNode* next = pcur->next;
		free(pcur);
		pcur = next;
	}
	p->size = 0;
	p->head = p->tail = NULL;
}